package org.csu.code.api.controller;

import org.csu.code.api.common.CommonResponse;
import org.csu.code.api.service.OrderService;
import org.csu.code.api.vo.OrderVO;
import org.csu.code.api.vo.typeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
//@RequestMapping("/order/")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @GetMapping("/accounts/{accountId}/orders")
    @ResponseBody
    public CommonResponse<List<OrderVO>> getOrdersByUserId(@PathVariable("accountId") int userId) {
        return orderService.getOrdersByUserId(userId);
    }

    @GetMapping("/orders/{id}")
    @ResponseBody
    public CommonResponse<OrderVO> getOrderByOrderId(@PathVariable("id") int orderId) {
        return orderService.getOrderByOrderId(orderId);
    }

    @PostMapping("/orders")
    @ResponseBody
    public CommonResponse<OrderVO> addOrder(@RequestBody OrderVO orderVO){
        return orderService.addOrder(orderVO);
    }

    @PutMapping("/orders/{id}")
    @ResponseBody
    public CommonResponse<String> changeOrderStatus(@PathVariable("id") int orderId, @RequestBody typeVO type){
        return orderService.changeOrderStatus(orderId, type);
    }

}
